//
//  WBHomeViewController.swift
//  传智微博
//
//  Created by 郑亚伟 on 16/11/3.
//  Copyright © 2016年 郑亚伟. All rights reserved.
//

import UIKit

/*********************************************************/
//定义全局变量，最好用private修饰，否则会全局使用。
private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {
     lazy var statusList = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    ///展示好友
   @objc func showFriends(){
       //TODO:打印当前方法名
        print(#function)
        let vc = WBDemoViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
    ///微博数据数组
    override func loadData() {
        for i in 0..<15{
            /****************************************/
            //这里是i.description
            statusList.insert(i.description, at: 0)
        }
    }

}

//MARK:表格数据源方法
extension WBHomeViewController{
    //重写父类的tableView的代理方法
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //1.去cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        //2.设置cell
        cell.textLabel?.text = statusList[indexPath.row]
        //3.返回cell
        return cell
    }
}


//MARK:设置界面
extension WBHomeViewController{
   override func setupUI() {
    //重写父类的方法
        super.setupUI()
        //设置导航栏按钮
      //无法高亮，所以自定义
        //navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style:.plain, target: self
        //, action: #selector(showFriends))
    //swift调用OC返回instancetype的方法 判断不出是否可选
//    let btn = UIButton.cz_textButton("好友", fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
//    btn?.addTarget(self, action: #selector(showFriends), for: .touchUpInside)
//    navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn!)
    
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", fontSize: 16, target: self, action: #selector(showFriends))
        //注册cell
    /********************************************************/
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
    
}
